package com.jpress.ejb;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import com.jpress.model.PaginaInterna;
import com.jpress.remote.PaginaInternaRemote;

@Stateless(mappedName="bean/paginainterna")
public class PaginaInternaEJB implements PaginaInternaRemote{

	@PersistenceContext(unitName="jpressEE")
	private EntityManager entityManager;	
	
	@Override
	public void inserir(PaginaInterna paginaInterna) throws Exception {
		try {
			entityManager.persist(paginaInterna);
		} catch (Exception e) {
			throw e;
		}		
	}

	@Override
	public void atualizar(PaginaInterna paginaInterna) throws Exception {
		try {
			entityManager.merge(paginaInterna);
		} catch (Exception e) {
			throw e;
		}		
	}

	@Override
	public void excluir(PaginaInterna paginaInterna) throws Exception {
		try {
			paginaInterna = entityManager.merge(paginaInterna);
			entityManager.remove(paginaInterna);
		} catch (Exception e) {
			throw e;
		}		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PaginaInterna> findAll() {
		Query query = entityManager.createNamedQuery("PaginaInterna.findAll");
		return (List<PaginaInterna>) query.getResultList();
	}

}
